﻿Imports WebSitePanel.SkinDesigner.Business.Css
Imports BoneSoft.CSS

Friend MustInherit Class CssCommandBase
    Inherits CommandBase
    Protected _file As CssFile
    Protected _selector As String
    Protected _previousvalue As String
    Protected _declaration As String
    Protected _term As Integer
    Protected _value As String
    Public Sub New(ByVal File As CssFile, ByVal Selector As String, ByVal Declaration As String, Optional ByVal Term As Integer = 0)
        _file = File
        _selector = Selector
        _declaration = Declaration
        _term = Term
    End Sub
    Friend NotOverridable Overrides Sub Execute()
        Dim t As Term = _file.GetCssValue(_selector, _declaration, _term)
        If t IsNot Nothing Then
            _previousvalue = t.Value
        Else
            _previousvalue = Nothing
        End If
        ChangeCss()
        onCssChanged(Me, New CssChangedEventArgs(_file.Name, _file.Text))
    End Sub
    Friend NotOverridable Overrides Sub Undo()
        If _previousvalue = Nothing Then
            _file.RemoveCssValue(_selector, _declaration, _value)
        Else
            _file.SetCssValue(_selector, _declaration, _previousvalue, _term)
        End If
        onCssChanged(Me, New CssChangedEventArgs(_file.Name, _file.Text))
    End Sub
    Friend MustOverride Sub ChangeCss()
End Class